CygNet Studio > Scripting in CygNet Studio > Scripting Examples > Storing and Retrieving a WatchList

Storing and Retrieving a WatchList

Using script, it is possible to store the list of points in a WatchList object for retrieval the next time the screen is open.

The following example simplifies the concept by using a Load and a Save button, which store and retrieve the list from the Dictionary object, respectively. WatchList data can also be stored on the file system or in another database format with the ImportFromXml and ExportToXml methods.

To Store and Retrieve a WatchList

  1. Create a new Studio screen.
  2. Add a WatchList object and two Button objects to the View. Name the WatchList control "watchList" and the two buttons "btnLoad" and "btnSave." Set the Text properties of these buttons to "Load List" and "Save List."  Set the [ButtonType] property for both buttons to Standard.
  3. Add script to the Save button.
  1. Open the Script Editor and navigate to btnSave EventClick event.
  2. Enter the following script to save the WatchList’s current list to the Dictionary object under "WatchList."

Sub btnSave_EventClick()

Dim This : Set This = btnSave

Dictionary.Value("WatchList") = watchList.ExportToXml

End Sub

  1. Add script to the Save and Load buttons.
  1. Navigate to btnLoad EventClick event.
  2. Enter the following script to load the WatchList from the Dictionary object. The Boolean parameter in ImportFromXml determines whether or not duplicate points will be replaced from the stored XML.

Sub btnLoad_EventClick()

Dim This : Set This = btnLoad

watchList.Clear

watchList.ImportFromXml Dictionary.Value("WatchList"), True

End Sub

  1. Save the screen and switch to Run mode. Add points to the WatchList by right-clicking the list and selecting Add Point.

Let us know how we can improve this topic.

CygNet at weatherford.com

© 2020 Weatherford. All rights reserved.